<template>
  <basic-dialog :visible="show"
                :title="`${type == 'add'? '新增': '编辑'}类型`"
                min-width="330px"
                @submit="submit"
                :isFullScreen="false"
  >
    <q-form  @submit="submit" greedy class="dialog-content">
      <div class="form-inline" style="padding: 20px 20px 0;">
        <yz-input
          :rules="[0]"
          v-model.trim="name"
          :maxlength="20"
          title="原因类型"
        />
      </div>
      <!-- 底部按钮 -->
      <q-separator />
      <div class="dialog-footer text-center margin-t-10">
        <q-btn outline label="取消" color="primary" @click="$emit('close')" class="q-mr-md"/>
        <q-btn unelevated label="确认" type="submit" color="primary"/>
      </div>
    </q-form>
  </basic-dialog>
</template>

<script>
export default {
  name: 'add-edit-defective',
  props: {
    show: {
      type: Boolean,
      default: false,
      required: true
    },
    type: {
      type: String,
      default: '',
      required: true
    },
    typeName: {
      default: ''
    }
  },
  data () {
    return {
      name: null
    }
  },
  methods: {
    submit () {
      if (this.type === 'add') {
        this.$emit('addReasonType', this.name)
      } else if (this.type === 'edit') {
        this.$emit('editReasonType', this.name)
      }
    }
  },
  watch: {
    show: function () {
      this.name = this.typeName
    }
  }
}
</script>

<style scoped lang="stylus">

</style>
